/*     */ package com.lmpop.trade.util;
/*     */ 
/*     */ import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;
/*     */ import java.io.IOException;
/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.net.URLDecoder;
/*     */ import javax.servlet.Filter;
/*     */ import javax.servlet.FilterChain;
/*     */ import javax.servlet.FilterConfig;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.ServletRequest;
/*     */ import javax.servlet.ServletResponse;
/*     */ import javax.servlet.http.Cookie;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import javax.servlet.http.HttpSession;
/*     */ 
/*     */ public class CookiesFilter
/*     */   implements Filter
/*     */ {
/*  23 */   private Hashtable users = new Hashtable();
/*     */ 
/*     */   public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException
/*     */   {
/*  27 */     HttpServletRequest request = (HttpServletRequest)req;
/*  28 */     HttpSession session = request.getSession(true);
/*  29 */     HttpServletResponse response = (HttpServletResponse)resp;
/*     */ 
/*  31 */     Cookie[] cookies = request.getCookies();
/*     */ 
/*  33 */     String session_user_id = ""; String session_cust_id = ""; String session_user_type = ""; String session_role_code = ""; String session_user_name = ""; String session_cust_class = ""; String session_cust_type = ""; String session_area_attr = "";
/*     */ 
/*  35 */     if ((cookies != null) && (cookies.length > 1))
/*     */     {
/*  37 */       session_user_id = getCookieValue(cookies, "session_user_id");
/*  38 */       session_cust_id = getCookieValue(cookies, "session_cust_id");
/*  39 */       session_user_type = getCookieValue(cookies, "session_user_type");
/*  40 */       session_role_code = getCookieValue(cookies, "session_role_code");
/*  41 */       session_user_name = getCookieValue(cookies, "session_user_name");
/*  42 */       session_cust_class = getCookieValue(cookies, "session_cust_class");
/*  43 */       session_cust_type = getCookieValue(cookies, "session_cust_type");
/*  44 */       session_area_attr = getCookieValue(cookies, "session_area_attr");
/*     */     }
/*  46 */     String requestUrL = request.getRequestURL().toString();
/*     */ 
/*  48 */     if (this.users.contains(session_user_id)) {
/*  49 */       session_user_id = "";
/*     */     } else {
/*  51 */       session.setAttribute("session_user_id", session_user_id);
/*  52 */       session.setAttribute("session_cust_id", session_cust_id);
/*  53 */       session.setAttribute("session_user_type", session_user_type);
/*  54 */       session.setAttribute("session_role_code", session_role_code);
/*  55 */       session.setAttribute("session_user_name", session_user_name);
/*  56 */       session.setAttribute("session_cust_class", session_cust_class);
/*  57 */       session.setAttribute("session_cust_type", session_cust_type);
/*  58 */       session.setAttribute("session_area_attr", session_area_attr);
/*  59 */       this.users.put(session_user_id, session);
/*     */     }
/*  61 */     if ((session_user_id.equals("")) && ((requestUrL.indexOf("program/member/") > -1) || (requestUrL.indexOf("program/admin/") > -1) || (requestUrL.indexOf("program/company/") > -1)))
/*  62 */       response.sendRedirect("/");
/*     */     else
/*  64 */       chain.doFilter(req, resp);
/*     */   }
/*     */ 
/*     */   public String getCookieValue(Cookie[] cookies, String name)
/*     */   {
/*  72 */     String value = "";
/*  73 */     if (cookies == null) {
/*  74 */       value = "";
/*     */     }
/*     */     else {
/*  77 */       for (int i = 0; i < cookies.length; i++)
/*     */       {
/*  79 */         if (name.equalsIgnoreCase(cookies[i].getName())) {
/*  80 */           if (name.equals("session_user_name"))
/*     */           {
/*     */             try
/*     */             {
/*  85 */               value = URLDecoder.decode(cookies[i].getValue(), "UTF-8");
/*     */             }
/*     */             catch (UnsupportedEncodingException e)
/*     */             {
/*  89 */               e.printStackTrace();
/*     */             }
/*     */ 
/*     */           }
/*     */           else
/*     */           {
/*  95 */             value = cookies[i].getValue();
/*     */           }
/*  97 */           return value;
/*     */         }
/*     */       }
/*     */     }
/* 101 */     return value;
/*     */   }
/*     */ 
/*     */   public void init(FilterConfig config)
/*     */     throws ServletException
/*     */   {
/*     */   }
/*     */ 
/*     */   public void destroy()
/*     */   {
/*     */   }
/*     */ }

/* Location:           F:\电商\commons-utils.jar
 * Qualified Name:     com.lmpop.trade.util.CookiesFilter
 * JD-Core Version:    0.6.0
 */